//////////////////////////////////
// Win32WrapperClass			//
//                              //
// File: Main.cpp               //
// Desc: Main entry point for   //
//			the splash app      //
//////////////////////////////////

#include "Main.h"

PortScannerWindow      *pWindow;


INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow) {
	
	PortScannerWindow      *pWindow;
	HACCEL					hAccel;
	HMENU					hMenu;

	// Define the dimensions of our app window
	RECT dimensions;
	dimensions.top		= 0;
	dimensions.left		= 0;
	dimensions.bottom	= 500;
	dimensions.right	= 500;
	
	// Load our Menu
	hMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));

	pWindow = new PortScannerWindow("RPSv1","Rutix Port Scanner",WS_OVERLAPPEDWINDOW|WS_VISIBLE,&dimensions,hMenu,hInstance);
	pWindow->Create(IDI_ICON1, IDI_ICON1);
	pWindow->Show();
	pWindow->BuildGUI();

	MSG Msg;
	HRESULT hRet;

	// Load our accelerator resource
	hAccel = LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_ACCELERATOR1));

	while( (hRet = GetMessage( &Msg, NULL, 0, 0 )) != 0)
	{ 
		if (hRet == -1) {
			// handle the error and possibly exit
			MessageBox(pWindow->getHWND(), "An unknown error has occurred!\nThe application will now terminate.", "Error!", MB_OK);
			PostQuitMessage(1);
		}
		else
		{
			if ( (!TranslateAccelerator(pWindow->getHWND(),hAccel,&Msg)) && (!IsDialogMessage(pWindow->getHWND(), &Msg)) ) {
				TranslateMessage(&Msg); 
				DispatchMessage(&Msg); 
			}
		}
	}

	delete (pWindow);
	return Msg.wParam;
}